#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
//typedef struct ListNode ListNode;
//struct ListNode* reverseList(struct ListNode* head) {
//    ListNode* cur = head;
//    ListNode* newnode = NULL;
//    while (cur)
//    {
//        ListNode* next = cur->next;
//        cur->next = newnode;
//        newnode = cur;
//        cur = next;
//    }
//    return newnode;
//}

/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */
struct ListNode* reverseList(struct ListNode* head) {
    if (head == NULL)
        return head;
    struct ListNode* n1 = NULL, * n2 = head, * n3 = head->next;
    while (n2) {
        n2->next = n1;
        n1 = n2;
        n2 = n3;
        if (n3)
            n3 = n3->next;
    }
    return n1;
}